﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace safehomeSimulation
{
    public  class utility
    {
        public enum ExceptionType 
        { TypeNormal, TypeSmoke, TypeCO, TypeTemperature, TypeWet, FireDisaster, WaterDisaster, CODisaster}
        public enum SensorType
        {
            TemperatureSensor, WetSensor, SmokeSensor, COSensor
        }

    }

    public class Msg
    {
        public utility.ExceptionType MId { get; set; }
        public string location { get; set; }
        public string ParaMessage { get; set; }

        public string ProcessMessage { get; set; }

        public Msg()
        {
            MId = utility.ExceptionType.TypeNormal;
            ParaMessage = string.Empty;
            ProcessMessage = string.Empty;
        }
    }


    public class Room
    {
        private TemperatureSensor _tsensor;
        private COSensor _csensor;
        private SmokeSensor _ssensor;
        private WetSensor _wsensor;

        public bool HasTSensor { get; set; }
        public bool HasCSensor { get; set; }
        public bool HasSSensor { get; set; }
        public bool HasWSensor { get; set; }

        public float Wet { get; set; }
        public float Temperature { get; set; }
        public float Smoke { get; set; }
        public float CO { get; set; }


        public Room()
        {
            HasTSensor = false;
            HasSSensor = false;
            HasWSensor = false;
            HasCSensor = false;
            _tsensor = new TemperatureSensor();
            _csensor = new COSensor();
            _ssensor = new SmokeSensor();
            _wsensor = new WetSensor();
                 
        }

        public void ConfigureSensorLocation(int loc)
        {
        }

        public void ConfigureT(float con)
        {
            _tsensor.SetCriticalPoint(con);
        }

        public void ConfigureS(float con)
        {
            _ssensor.SetCriticalPoint(con);
        }

        public void ConfigureCO(float con)
        {
            _csensor.SetCriticalPoint(con);
        }

        public void ConfigureW(float con)
        {
            _wsensor.SetCriticalPoint(con);
        }

        public void Environment(float T, float C, float S, float W)
        {
            Wet = W;
            Temperature = T;
            CO = C;
            Smoke = S;
        }

        public void CaptureEnvironment()
        {
            if (HasCSensor)
                _csensor.CaptureEnvironment(CO);
            if (HasSSensor)
                _ssensor.CaptureEnvironment(Smoke);
            if (HasTSensor)
                _tsensor.CaptureEnvironment(Temperature);
            if (HasWSensor)
                _wsensor.CaptureEnvironment(Wet);

        }

        public List<Msg> GetAllMsg()
        {
            List<Msg> result = new List<Msg>();
            if (HasWSensor)
            {
                Msg msg = _wsensor.GetMsg();
                msg.ParaMessage = Wet.ToString();
                result.Add(msg);
            }
            if (HasSSensor)
            {
                Msg msg = _ssensor.GetMsg();
                msg.ParaMessage = Smoke.ToString();
                result.Add(msg);
            }
            if (HasTSensor)
            {
                Msg msg = _tsensor.GetMsg();
                msg.ParaMessage = Temperature.ToString();
                result.Add(msg);
            }
            if (HasCSensor)
            {
                Msg msg = _csensor.GetMsg();
                msg.ParaMessage = CO.ToString();
                result.Add(msg);
            }
            return result;
           
        }
    }
}
